package com.usian.skill.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.skill.mapper.GoodsMapper;
import com.usian.skill.pojo.Goods;
import com.usian.skill.service.GoodsService;
import com.usian.skill.vo.GoodsDetailVo;
import com.usian.skill.vo.GoodsVo;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Resource
    private GoodsMapper goodsMapper;

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    /**
     * 商品列表查询
     * @return
     */
    @Override
    public List<GoodsVo> findAll() {
        //从redis中获取数据
        List list = JSON.parseArray(stringRedisTemplate.opsForValue().get("goods"),GoodsVo.class);
        return list;
    }


    /**
     * 商品的详情
     * @param id
     * @return
     */
    @Override
    public GoodsVo goodsVoById(Long id) {

        GoodsVo goodsVo = JSON.parseObject(stringRedisTemplate.opsForValue().get(id.toString()), GoodsVo.class);


        return goodsVo;
    }

    @Override
    public List<GoodsVo> findAllDB() {
        return goodsMapper.findList();
    }

    @Override
    public GoodsVo goodsVoByIdDB(Long id) {
        return goodsMapper.goodsVoById(id);
    }


}
